home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_std / exceptions.e < prev    next >
Text File  |  1998-12-22  |  4KB  |  148 lines

  1. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  2. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  3. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  4. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  5. -- this header is kept unaltered, and a notification of the changes is added.
  6. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  7. -- another product.
  8. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  9. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  10. --                       http://www.loria.fr/SmallEiffel
  11. --
  12. class EXCEPTIONS
  13.    --
  14.    -- Facilities for adapting the exception handling mechanism.
  15.    -- This class may be used as ancestor by classes needing its 
  16.    -- facilities.
  17.    --
  18.  
  19. feature -- Various exceptions codes :
  20.  
  21.    Check_instruction: INTEGER is 1;
  22.      -- Exception code for violated check.
  23.  
  24.    Class_invariant: INTEGER is 2;
  25.      -- Exception code for violated class invariant.
  26.  
  27.    Developer_exception: INTEGER is 3;
  28.      -- Exception code for developer exception.
  29.  
  30.    Incorrect_inspect_value: INTEGER is 4;
  31.      -- Exception code for inspect value which is not one
  32.      -- of the inspect constants, if there is no Else_part
  33.  
  34.    Loop_invariant: INTEGER is 5;
  35.      -- Exception code for violated loop invariant
  36.  
  37.    Loop_variant: INTEGER is 6;
  38.      -- Exception code for non-decreased loop variant
  39.  
  40.    No_more_memory: INTEGER is 7;
  41.      -- Exception code for failed memory allocation
  42.  
  43.    Postcondition: INTEGER is 8;
  44.      -- Exception code for violated postcondition.
  45.  
  46.    Precondition: INTEGER is 9;
  47.      -- Exception code for violated precondition.
  48.  
  49.    Routine_failure: INTEGER is 10;
  50.      -- Exception code for failed routine.
  51.  
  52.    Os_signal: INTEGER is 11;
  53.      -- Exception code for a signal received from the OS.
  54.  
  55.    Void_attached_to_expanded: INTEGER is 12;
  56.      -- Exception code for attachment of void value
  57.      -- to expanded entity.
  58.  
  59.    Void_call_target: INTEGER is 13;
  60.      -- Exception code for feature applied to void reference
  61.  
  62. feature
  63.  
  64.    developer_exception_name: STRING is
  65.      -- Name of last developer-raised exception.
  66.       require
  67.      applicable: is_developer_exception
  68.       do
  69.      Result := developer_exception_name_memory.item;
  70.       end;
  71.  
  72.    is_developer_exception: BOOLEAN is
  73.      -- Is the last exception originally due to
  74.      -- a developer exception?
  75.       do
  76.      Result := exception = Developer_exception;
  77.       end;
  78.  
  79.    is_developer_exception_of_name (name: STRING): BOOLEAN is
  80.      -- Is the last exception originally due to a developer
  81.      -- exception of name `name'?
  82.       do
  83.      if is_developer_exception then
  84.         Result := name.is_equal(developer_exception_name);
  85.      end;
  86.       end;
  87.  
  88. feature -- Status report :
  89.  
  90.    assertion_violation: BOOLEAN is
  91.      -- Is last exception originally due to a violated
  92.      -- assertion or non-decreasing variant?
  93.       do            
  94.      inspect 
  95.         exception
  96.      when Check_instruction, Class_invariant, Loop_invariant,
  97.           Loop_variant, Postcondition, Precondition then
  98.         Result := true;
  99.      else
  100.      end;
  101.       end;
  102.  
  103.    exception: INTEGER is
  104.      -- Code of last exception that occurred.
  105.       external "SmallEiffel"
  106.       end;
  107.  
  108.    is_signal: BOOLEAN is
  109.      -- Is last exception originally due to an external
  110.      -- event (operating system signal) ?
  111.       do
  112.       end;
  113.  
  114. feature -- Basic operations :
  115.  
  116.    die(code: INTEGER) is
  117.      -- Terminate execution with exit status code,
  118.      -- without triggering an exception.
  119.       do
  120.      die_with_code(code);
  121.       end;
  122.  
  123.    raise(name: STRING) is
  124.      -- Raise a developer exception of name name.
  125.       do
  126.      developer_exception_name_memory.set_item(name);
  127.      raise_exception(Developer_exception);
  128.       end;
  129.  
  130. feature -- Non-Standard Extensions :
  131.  
  132.    signal_number: INTEGER is
  133.      -- Signal Number received from OS.  Zero if exception
  134.      -- is not an OS signal.
  135.       external "SmallEiffel"
  136.       end;
  137.  
  138.    developer_exception_name_memory: MEMO[STRING] is
  139.       once
  140.      !!Result;
  141.       end;
  142.  
  143.    raise_exception(code: INTEGER) is
  144.       external "SmallEiffel"
  145.       end;
  146.  
  147. end -- EXCEPTIONS
  148.